package com.householditemtwo.index.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.householditemtwo.common.entity.Carousel;
import com.householditemtwo.common.entity.Compary;
import com.householditemtwo.common.entity.News;
import com.householditemtwo.common.entity.Newstype;
import com.householditemtwo.common.entity.Product;
import com.householditemtwo.common.entity.Producttype;
import com.householditemtwo.common.entity.Produtimg;
import com.householditemtwo.common.utils.DBManager;
import com.householditemtwo.common.utils.QueryDataResult;

/**
 * 页面DAO
 * @author admin
 *
 */

/**
 * 首页DAO
 * @author admin
 *
 */

public class IndexDao {
	
	/**
	 * 查询所有轮播图
	 * @return
	 */
		public List<Carousel> selectAllCarousel(){
		
			DBManager db=new DBManager();
			String sql="select * from carousel order by crWeight desc";
			QueryDataResult qdr=db.executeQuery(sql);
			Carousel emp=new Carousel();
			ArrayList<Carousel> list=new ArrayList<Carousel>();
			try {
				while(qdr.rs.next()) {
					Carousel c=new Carousel();
					c.setCrimgid(qdr.rs.getInt(1));
					c.setCrurl(qdr.rs.getString(2));
					c.setProid(qdr.rs.getInt(3));
					c.setCrweight(qdr.rs.getInt(4));
					list.add(c);
				}
			}catch(SQLException e) {
				e.printStackTrace();
			}
			
			//返回查询的结果
			return list;
			
			
		
		}
		
		/**
		 * 查询公司信息
		 * @return
		 */
			public List<Compary> selectAllCompary(){
			
				DBManager db=new DBManager();
				String sql="select * from compary ";
				QueryDataResult qdr=db.executeQuery(sql);
				Carousel emp=new Carousel();
				ArrayList<Compary> list=new ArrayList<Compary>();
				try {
					while(qdr.rs.next()) {
						Compary c=new Compary();
						c.setCpyid(qdr.rs.getInt(1));
						c.setCpyname(qdr.rs.getString(2));
						c.setCpylogo(qdr.rs.getString(3));
						c.setCpyculture(qdr.rs.getString(4));
						c.setCpysimintro(qdr.rs.getString(5));
						c.setCpydeiIntro(qdr.rs.getString(6));
						c.setCpyaddress(qdr.rs.getString(7));
						c.setCpyphone(qdr.rs.getString(8));
						c.setCpyemail(qdr.rs.getString(9));
						list.add(c);
					}
				}catch(SQLException e) {
					e.printStackTrace();
				}
				
				//返回查询的结果
				return list;
				
				
			
			}
			/**
			*查询产品
			 * @return
			 */

		public List<Producttype> selectAllProducttype() {
			DBManager db=new DBManager();
			String sql="select * from producttype ";
			QueryDataResult qdr=db.executeQuery(sql);
			Carousel emp=new Carousel();
			ArrayList<Producttype> list=new ArrayList<Producttype>();
			try {
				while(qdr.rs.next()) {
					Producttype c=new Producttype();
					c.setPteid(qdr.rs.getInt(1));
					c.setPtename(qdr.rs.getString(2));
					list.add(c);
				}
			}catch(SQLException e) {
				e.printStackTrace();
			}
			
			//返回查询的结果
			return list;
			
			
			
		
		
		}
		/**
		*查询精选产品
		 * @return
		 */

			public List<Product> selectAllProduct() {
				DBManager db=new DBManager();
				String sql="select * from Product order by proid limit 6 ";
				QueryDataResult qdr=db.executeQuery(sql);
				Product emp=new Product();
				ArrayList<Product> list=new ArrayList<Product>();
				try {
					while(qdr.rs.next()) {
						Product c=new Product();
						c.setProid(qdr.rs.getInt(1));
						c.setProname(qdr.rs.getString(2));
						c.setProprice(qdr.rs.getDouble(3));
						c.setProstock(qdr.rs.getInt(4));
						c.setPteid(qdr.rs.getInt(5));
						c.setProresult(qdr.rs.getString(6));
						c.setProdefauiimg(qdr.rs.getString(7));
						c.setProchoice(qdr.rs.getInt(8));
						c.setProplace(qdr.rs.getString(9));
						c.setPromaterial(qdr.rs.getString(10));
						c.setProunit(qdr.rs.getString(11));
						c.setProshell(qdr.rs.getString(12));
						c.setPropaint(qdr.rs.getString(13));
						
						list.add(c);
					}
				}catch(SQLException e) {
					e.printStackTrace();
				}
				
				
				//返回查询的结果
				return list;
			}

			
			//查询出新闻分类
			public List<Newstype> selectNewstype() {
				DBManager db=new DBManager();
				String sql="select * from newstype  ";
				QueryDataResult qdr=db.executeQuery(sql);
				Carousel emp=new Carousel();
				ArrayList<Newstype> list=new ArrayList<Newstype>();
				try {
					while(qdr.rs.next()) {
						Newstype c=new Newstype();
						c.setNewstypeid(qdr.rs.getInt(1));
						c.setNewstypename(qdr.rs.getString(2));
						list.add(c);
					}
				}catch(SQLException e) {
					e.printStackTrace();
				}
				
				//返回查询的结果
				return list;
				
			}
			

			
				public List<News> selectNews() {
					DBManager db=new DBManager();
					String sql="select * from news order by newsTime desc limit 4 ";
					QueryDataResult qdr=db.executeQuery(sql);
					Carousel emp=new Carousel();
					ArrayList<News> list=new ArrayList<News>();
					try {
						while(qdr.rs.next()) {
							News c=new News();
						   c.setNewsid(qdr.rs.getInt(1));
						   c.setNewstitle(qdr.rs.getString(2));
						   c.setNewscontent(qdr.rs.getString(3));
						   c.setNewsdetails(qdr.rs.getString(4));
						   c.setNewstypeid(qdr.rs.getInt(5));
						   c.setNewstime(qdr.rs.getString(6));
						   c.setNewsclick(qdr.rs.getInt(7));
						   c.setNewschoice(qdr.rs.getString(8));
						   c.setNewsimg(qdr.rs.getString(9));
						   list.add(c);
						}
					}catch(SQLException e) {
						e.printStackTrace();
					}
					
					//返回查询的结果
					return list;
					
				}



				public News selectNewsById(int newid) {
					DBManager db=new DBManager();
					String sql="select * from news order by newsTime desc ";
					QueryDataResult qdr=db.executeQuery(sql);
					Carousel emp=new Carousel();
					News c=new News();
					try {
						while(qdr.rs.next()) {
							
						   c.setNewsid(qdr.rs.getInt(1));
						   c.setNewstitle(qdr.rs.getString(2));
						   c.setNewscontent(qdr.rs.getString(3));
						   c.setNewsdetails(qdr.rs.getString(4));
						   c.setNewstypeid(qdr.rs.getInt(5));
						   c.setNewstime(qdr.rs.getString(6));
						   c.setNewsclick(qdr.rs.getInt(7));
						   c.setNewschoice(qdr.rs.getString(8));
						   c.setNewsimg(qdr.rs.getString(9));
						   
						}
					}catch(SQLException e) {
						e.printStackTrace();
					}
					//返回查询的结果
					return c;
					
				}
		
}
